<?php

require_once('php/lib/configured_object.php');

config('Controller', 'controller');

/**
 * Abstract controller.
 *
 * @abstract
 * @author Pascal de Vink
 */
class Controller extends ConfiguredObject {

	function getLang($string) {
		
		if ($_SESSION[language] == NULL) {
			require('lang/nl.php');
		} else {
			require('lang/'.$_SESSION[language].'.php');
		}
		
		if ($lang[''.$string] !== null) {
			return $lang[''.$string];	
		} else {
			return 'empty';
		}
		
	}
	
	function checkPostData($array) {
		foreach ($array as $key => $value) {
			if ($_POST[$value] == '' || $_POST[$value] == null) {
				return false;
			}
		}
		return true;
	}
	
	function checkLength($value, $minsize, $maxsize) {
		if (strlen($value) < $minsize || strlen($value) > $maxsize) {
			return false;
		}
		return true;
	}
	
	function checkValueForAnomalies($var) {
		if (!ereg("^[_a-zA-Z0-9-]*$", $var)) {
			return false;
		}
		return true;
	}
	
	function checkValueForHTTPAnomalies($var) {
		if (!ereg("^((([a-zA-Z0-9_-]*).?([a-zA-Z0-9_-]*))|(([a-zA-Z0-9_-]*).?([a-zA-Z0-9_-]*).?([a-zA-Z0-9_-]*)))/?([a-zA-Z0-9/?=~_-]*)$", $var)) {
			return false;
		}
		return true;
	}
	
	function checkValue($var, $value_array) {
		foreach ($value_array as $value) {
			if ($var == $value) {
				return true;
			}
		}
		return false;
	}
	
}
?>